<script>
	var doupdate='__URL__/doupdate';
	var obj=new Object();
	var addormdf="{$id}";
	obj["{$lowmdmk}"+"id"]="{$id}";
</script>
<!--table部分-->
<div class='col-md-12' style='padding-top: 20px'>
	<!--开始-->
	<table class='table table-hover table-striped table-bordered'>
		<tbody>

			<tr><td>用户名</td><td><input id='usrnm' value="{$mo['usrnm']}"></td></tr>
			<tr><td>真名</td><td><input id='usrnn' value="{$mo['usrnn']}"></td></tr>
			<tr><td>类型</td><td>
			<select id='f_usr_typeid'>
				<option value='0'>无</option>
				<volist name='f_usr_typeid' id='v'><option value="<?php echo $v['typeid'] ?>"><?php echo $v['typenm'] ?></option></volist>
			</select>
			<script>var k="f_usr_typeid";var v="{$moforjs[f_usr_typeid]}";if(k.indexOf('_')!=-1&&v==''){$('#'+k).val('0');}else{$('#'+k).val(v);}</script>
			</td></tr>
			<tr id='line' <?php if(!$mo['f_usr_lineid']){ ?>style="display:none"<?php } ?>><td>产线</td><td>
			<select id='f_usr_lineid'>
				<option value='0'>无</option>
				<volist name='f_usr_lineid' id='v'><option value="<?php echo $v['lineid'] ?>"><?php echo $v['linenm'] ?></option></volist>
			</select>
			<tr id='banci' <?php if(!$mo['f_usr_banciid']){ ?>style="display:none"<?php } ?>><td>班次</td><td>
			<select id='f_usr_banciid'>
				<option value='0'>无</option>
				<volist name='f_usr_banciid' id='v'><option value="<?php echo $v['banciid'] ?>" id='opt_{$v[banciid]}'><?php echo $v['bancinm'] ?></option></volist>
			</select>
			<script>var k="f_usr_banciid";var v="{$moforjs[f_usr_banciid]}";if(k.indexOf('_')!=-1&&v==''){$('#'+k).val('0');}else{$('#'+k).val(v);}</script>
			</td></tr>
			<tr id='fenzu' <?php if(!$mo['f_usr_fenzuid']){ ?>style="display:none"<?php } ?>><td>分组</td><td>
			<select id='f_usr_fenzuid'>
				<option value='0'>无</option>
				<volist name='f_usr_fenzuid' id='v'><option value="<?php echo $v['fenzuid'] ?>"><?php echo $v['fenzunm'] ?></option></volist>
			</select>
			<script>var k="f_usr_fenzuid";var v="{$moforjs[f_usr_fenzuid]}";if(k.indexOf('_')!=-1&&v==''){$('#'+k).val('0');}else{$('#'+k).val(v);}</script>
			</td></tr>
			

			
		</tbody>
	</table>
	<a class='btn btn-primary' id='update'><?php if($id==0){ ?>添加<?php }else{ ?>修改<?php } ?></a>
</div>

<script>

//#########
$(function(){
	$('#update').click(function(){

		var typeid=$('#f_usr_typeid').val();
		var lineid=$('#f_usr_lineid').val();
		var banciid=$('#f_usr_banciid').val();
		var fenzuid=$('#f_usr_fenzuid').val();

		if(typeid==2&&lineid==0){msg('请选择产线');return;}
		if(typeid==3&&fenzuid==0){msg('请选择分组');return;}
		if(typeid!=1&&banci==0){msg('请选择班次');return;}
		
		obj['usrnm']=$('#usrnm').val();
		obj['usrnn']=$('#usrnn').val();
		obj['f_usr_typeid']=$('#f_usr_typeid').val();
		obj['f_usr_lineid']=$('#f_usr_lineid').val();
		obj['f_usr_banciid']=$('#f_usr_banciid').val();
		obj['f_usr_fenzuid']=$('#f_usr_fenzuid').val();

		

		$.ajax({
            'type': 'GET',
            'url':doupdate,
            'async':false,  
            'contentType': 'application/json',
            'data': obj,
            'dataType': 'json',
            'success': function(data) {
            	var str='';
            	if(data['pattern']=='0'){str='添加';}else{str='修改';}
            	msg(str+'成功！点击返回',2);
            	console.log("success");
            },
            'error':function() {
                console.log("error");
            }
        });
	})

	$('#f_usr_typeid').change(function(){
		canshuqingling();
		var v=$('#f_usr_typeid').val();
		if(v==2){
			$('#line').show();
			$('#opt_4').show();
			$('#banci').show();
			$('#fenzu').hide();
		}else if(v==3){
			$('#line').hide();
			$('#opt_4').hide();
			$('#banci').show();
			$('#fenzu').show();
		}else{
			$('#line').hide();
			$('#banci').hide();
			$('#fenzu').hide();
		}
	})
})
function canshuqingling(){
	$('#f_usr_lineid').val(0);
	$('#f_usr_fenzuid').val(0);
	$('#f_usr_banciid').val(0);
}
</script>